/**
 * 库存价格查询builder
 * 
 * @author 魏文杰 
 * @Version 1.0
 * @Date 2013-10-08
 */

package ext.generic.erp.mvc.builders;

import java.util.ArrayList;
import java.util.List;

import wt.part.WTPart;
import wt.util.WTException;

import com.ptc.mvc.components.AbstractComponentBuilder;
import com.ptc.mvc.components.ColumnConfig;
import com.ptc.mvc.components.ComponentBuilder;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfigFactory;
import com.ptc.mvc.components.ComponentParams;
import com.ptc.mvc.components.TableConfig;
import com.ptc.mvc.util.ClientMessageSource;

import ext.generic.erp.bean.GenericIEBean;
import ext.generic.erp.query.InventoryPriceIETask;

@ComponentBuilder({"query.inventory.price"})
public class QueryInventoryPriceBuilder extends AbstractComponentBuilder {
	private static final String RESOURCE = "ext.generic.erp.manually.IntegrationResource";
	private ClientMessageSource messageSource = null ;

	public QueryInventoryPriceBuilder() {
	    this.messageSource = getMessageSource( RESOURCE );
	}
	
	@Override
	public Object buildComponentData(ComponentConfig componentConfig , ComponentParams componentParams) throws Exception {
		System.out.println(">>>>> Entering In QueryInventoryPriceBuilder.buildComponentData......") ;
		List<GenericIEBean> list = null ;
		
		Object contextObject = componentParams.getContextObject();
		
		if( contextObject != null && contextObject instanceof WTPart ){
			WTPart part = ( WTPart ) contextObject ;
			
			//查询零部件的库存和价格
			list = InventoryPriceIETask.query(part);
		}else{
			if( contextObject == null ){
				System.out.println("QueryInventoryPriceBuilder.buildComponentData , contextObject == null")  ;
			}else{
				System.out.println("QueryInventoryPriceBuilder.buildComponentData , contextObject class type : " + contextObject.getClass())  ;
			}
		}
		
		if( list == null ){
			System.out.println("QueryInventoryPriceBuilder.buildComponentData , list == null")  ;
			
			list = new ArrayList<GenericIEBean>();
		}
		
		System.out.println(">>>>> Existed Out QueryInventoryPriceBuilder.buildComponentData......") ;
		
		return list;
	}

	@Override
	public ComponentConfig buildComponentConfig(ComponentParams componentParams) throws WTException {
		System.out.println(">>>>> Entering In QueryInventoryPriceBuilder.buildComponentConfig......") ;
		
		ComponentConfigFactory componentConfigFactory = getComponentConfigFactory();
		
		TableConfig tableConfig = componentConfigFactory.newTableConfig();

		tableConfig.setId("query.inventory.price");
		tableConfig.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_LABEL"));
		tableConfig.setConfigurable(false);

		ColumnConfig number = componentConfigFactory.newColumnConfig("number", true);
		number.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_NUMBER"));
		number.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(number);

		ColumnConfig name = componentConfigFactory.newColumnConfig("name", false);
		name.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_NAME"));
		name.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(name);

		ColumnConfig orgCode = componentConfigFactory.newColumnConfig("orgCode", false);
		orgCode.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_ORG_CODE"));
		orgCode.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(orgCode);
		
		ColumnConfig partPrice = componentConfigFactory.newColumnConfig("partPrice", false);
		partPrice.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_PRICE"));
		partPrice.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(partPrice);

		ColumnConfig partInventory = componentConfigFactory.newColumnConfig("partInventory", false);
		partInventory.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_INVENTORY"));
		partInventory.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(partInventory);

		ColumnConfig unit = componentConfigFactory.newColumnConfig("unit", false);
		unit.setLabel(this.messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_UNIT"));
		unit.setDataUtilityId("queryInventoryPrice") ;
		tableConfig.addComponent(unit);

		System.out.println(">>>>> Existed Out QueryInventoryPriceBuilder.buildComponentConfig......") ;
		
		return tableConfig;
	}

}
